package com.android.gilastv.dialog;

import android.text.TextUtils;
import android.view.View;

import androidx.fragment.app.FragmentActivity;

import com.android.baselibrary.dialog.BaseDialogFragment;
import com.android.baselibrary.interface_.OkHttpCallBack;
import com.android.baselibrary.responce.BaseResponce;
import com.android.baselibrary.tool.CommToast;
import com.android.baselibrary.view.Comm_EditView;
import com.android.gilastv.R;
import com.android.gilastv.constants.Constants;
import com.android.gilastv.manager.API_Manager;

import java.util.Map;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 反馈
 */

public class Feedbak_DialogFragment extends BaseDialogFragment {

    @BindView(R.id.et_content)
    Comm_EditView et_content;
    @BindView(R.id.et_phone)
    Comm_EditView et_phone;

    @Override
    protected int getLayoutId() {
        return R.layout.dialog_fankui;
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initView() {
    }

    @Override
    protected boolean isImmersionBarEnabled() {
        return false;
    }

    @Override
    protected boolean setCanceledOnTouchBACK() {
        return true;
    }

    @Override
    protected int getShowDirection() {
        return BaseDialogFragment.Direction_FadeIn;
    }

    @Override
    public void setData(Map<String, Object> params) {
        if (params != null) {

        }
    }

    public static BaseDialogFragment showDialog(FragmentActivity activity, Map<String, Object> params) {
        Feedbak_DialogFragment dialogFragment = new Feedbak_DialogFragment();
        dialogFragment.setData(params);
        dialogFragment.show(activity.getSupportFragmentManager(), "");
        return dialogFragment;
    }


    @OnClick({R.id.csb_submit})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.csb_submit:
                feedback();
                break;
        }
    }

    private void feedback() {
        String content = et_content.getText();
        String phone = et_phone.getText();
        if (TextUtils.isEmpty(content)) {
            CommToast.showToast(mContext, "请输入内容");
            et_content.requestFocus();
            return;
        }
        if (TextUtils.isEmpty(phone)) {
            CommToast.showToast(mContext, "请输入联系方式");
            et_phone.requestFocus();
            return;
        }
        API_Manager.feedback(mContext, content, phone, new OkHttpCallBack<BaseResponce<String>>() {
            @Override
            public void onSuccess(BaseResponce<String> baseResponce) {
                CommToast.showToast(mContext, "提交成功");
                dismissWithAnim();
            }

            @Override
            public void onFailure(BaseResponce<String> baseResponce) {
                CommToast.showToast(mContext, Constants.NetError);
            }
        });

    }


}
